package model;
import java.util.HashMap;

/**
 * 
 * This class portraits a daily workout. The class contains a list of
 * exercises and workouts and clients can manually add an exercise/workout
 * to the list. 
 * @author Roman Pusec, Dennis Goldfinger, Marko Bilic
 *
 */
public class Workout extends Activity {
	
	private HashMap<Activity, Integer> activityMap;
	
	/**
	 * Constructor which sets the name of the workout. 
	 * @param name The name of the workout. 
	 */
	public Workout(String name) 
	{
		super(name);
		activityMap = new HashMap<Activity, Integer>();
	}
	
	/**
	 * Adds an activity to the list of activities. 
	 * @param activity The activity. 
	 * @param quantity The quantity. 
	 */
	public void addExercise(Activity activity, int quantity)
	{
		if(!activityMap.containsKey(activity))
			activityMap.put(activity, quantity); 
	}
	
	/**
	 * Removes a certain activity from the list. 
	 * @param activity Activity to delete. 
	 */
	public void removeExercise(Activity activity)
	{
		if(activityMap.containsKey(activity))
			activityMap.remove(activity);
	}
	
	/**
	 * Returns the name of the workout. 
	 */
	public String getName()
	{
		return this.name;
	}
	
	/**
	 * Sets the name of the workout. 
	 * @param newName The new name of the workout. 
	 */
	public void setName(String newName)
	{
		this.name = newName;
	}
	
	/**
	 * Returns the list of activities. 
	 * @return The list of activities. 
	 */
	public HashMap<Activity, Integer> getActivities()
	{
		return activityMap;
	}
	
	/**
	 * Overridden toString() method which displays all of the information from the 
	 * given Workout object. It displays the initial information as well as the 
	 * activities from the activities list. 
	 */
	public String toString()
	{
		String temp = "-- " + this.name + " -- \n" + "Workouts: ";
		Object[] keys = activityMap.keySet().toArray();
		Object[] values = activityMap.values().toArray();
		
		for(int i = 0; i < activityMap.size(); i++)
		{
			temp += "\n\tExercise: " + ((Activity)keys[i]).name + "\n\tQuantity: " + values[i];
		}
		
		temp += "\n-----------------------------------------\n";
		
		return temp;
	}
}
